import $http from '../../../servers/http';
import { Result } from 'seats/schema/Result';
import {
  ExportRequest,
  OperationlogsRequest,
  OperationlogsResponse,
  TypeResponse,
} from 'admin/schema/OperationLog';

/**获取操作类型列表*/
export const getOperationTypeList = (): Promise<Result<TypeResponse>> => {
  return $http.get({
    url: `/sso/systemlogmanage/operationlogs/type`,
  });
};

/**查询【操作日志】列表 */
export const getOperationLogsList = (
  data: OperationlogsRequest
): Promise<Result<OperationlogsResponse>> => {
  // get请求，需要转换操作类型数组
  let operationTypeStr = '';

  data.operationType?.forEach(type => {
    operationTypeStr += `operationType=${type}&`;
  });

  delete data.operationType;

  return $http.get({
    url: `/sso/systemlogmanage/operationlogs?${operationTypeStr}`,
    data,
  });
};

/**创建【操作日志】下载任务-导出 */
export const createOperationLogsDownloadTask = (data: ExportRequest): Promise<Result<null>> => {
  return $http.post({
    url: '/icms/taskmanage/report/operationlogs/export',
    data,
  });
};
